﻿<%@ Page Language="C#" AutoEventWireup="true" %>
<script runat="server">
            
    protected void Page_Load(object sender, EventArgs e)
    {
        int id = HL.Core.Web.HttpQueryString.GetValue("id").ToInt();
        if (id > 0)
        {
            var news = ModNewsService.Instance.GetByID(id);
            if (news != null)
            {
                news.Download++;
                ModNewsService.Instance.Save(news, o => o.Download);

                Response.Clear();
                Response.ContentType = "application/octet-stream";
                Response.AppendHeader("Content-Disposition", "attachment; filename=" + System.IO.Path.GetFileName(news.File));
                
                if (news.File.StartsWith("~/"))
                    Response.WriteFile(Server.MapPath(news.File));
                else
                    Response.WriteFile(news.File);

                Response.End();
            }
        }
    }
    
</script>